
/**
------------------------------------------------------------
* NGUYEN SY BACH
* bit.mta@gmail.com
* Hoc Vien Ky Thuat Quan Su
------------------------------------------------------------
*** Help cho cuda
------------------------------------------------------------
*/

#ifndef NSB_HELPER_H
#define NSB_HELPER_H

#pragma once

#include "cuda_runtime.h"
#include <stdio.h>
#include <stdlib.h>


typedef unsigned int uint;
typedef unsigned char uchar;

typedef struct tagPoint2f
{
	double x;
	double y;
	tagPoint2f(){
		x = 0, y = 0;
	}
	tagPoint2f(double _x, double _y){
		x = _x, y = _y;
	}
} Point2f;


enum
{
	NEARESTNEIGHBOR,
	BILINEAR,
	BICUBIC,
};


inline void HandleError(cudaError_t err,
	const char *file,
	int line) {
	if (err != cudaSuccess) {
		printf("%s: [%s , %d]\n", cudaGetErrorString(err),
			file, line);
		exit(EXIT_FAILURE);
	}
}

#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

#define HANDLE_NULL(ptr) if (!ptr){\
	fprintf(stderr, #ptr" = NULL: [%s , %d]\n", __FILE__, \
	__LINE__); \
	exit(EXIT_FAILURE); }

#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#define MAX3(a,b,c) ((a) > MAX(b,c) ? (a) : MAX(b,c))
#define MIN3(a,b,c) ((a) < MIN(b,c) ? (a) : MIN(b,c))
#define CUBE(x) ((x)*(x)*(x))
#define SQUARE(x) ((x)*(x))
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define INDEX(x,y,stride,channels) ((y)*(stride) + (x)*(channels))
#define CEIL(x) (x > 0 ? ceil(x) : floor(x))
#define FLOOR(x) ( x < 0 ? floor(x) : ceil(x))
#define BYTE uchar


#endif